package edu.ilstu.mind.ise.module.arduino.serial;

import java.io.IOException;

public interface SerialCommunicator {

	/**
	 * Connect to the Arduino Controller
	 */
	void connect() throws IOException;

	/**
	 * Disconnect from the Arduino Controller
	 */
	void disconnect();

	/**
	 * Lock read/write operations from other threads
	 */
	void lock();

	/**
	 * Unlock read/write operations from other threads. This must be called by
	 * the thread that called lock()
	 */
	void unlock();
	

	/**
	 * Write a single byte
	 * 
	 * @param b
	 *            Byte to write
	 */
	void write(byte b) throws IOException;

	/**
	 * Write an entire byte buffer
	 * 
	 * @param buffer
	 *            Buffer to write
	 */
	void write(byte[] buffer) throws IOException;

	/**
	 * Write a byte buffer
	 * 
	 * @param buffer
	 *            Buffer to write
	 * @param offset
	 *            Offset of the buffer to start writing from
	 * @param len
	 *            Number of bytes to write
	 */
	void write(byte[] buffer, int offset, int len) throws IOException;

	/**
	 * Read a single byte
	 * 
	 * @return The byte read
	 */
	byte read() throws IOException;

	/**
	 * Read to byte buffer
	 * 
	 * @param buffer
	 *            Buffer to write to
	 * @param offset
	 *            Offset of buffer to start writing to
	 * @param len
	 *            Number of bytes to read
	 */
	void read(byte[] buffer, int offset, int len) throws IOException;
}
